//nolint:lll
package resolver

/*
Copyright 2021-2025 The k8gb Contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
*/

import (
	"github.com/k8gb-io/k8gb/controllers/utils"
	corev1 "k8s.io/api/core/v1"
)

// https://github.com/go-playground/validator
// https://github.com/go-playground/validator/blob/master/validator_test.go
// https://github.com/alecthomas/kong

type Config struct {
	ClusterGeoTag string `env:"CLUSTER_GEO_TAG" required:"" validate:"geotag" help:"ClusterGeoTag to determine specific location"`

	DNSZones string `env:"DNS_ZONES" required:"" help:"pairs of dnsZone ad edgeDNSZone, eg: DNS_ZONES=example.com:cloud.example.com;example.io:cloud.example.io"`

	ParentZoneDNSServersRaw []string `env:"EDGE_DNS_SERVERS" optional:"" validate:"unique,dive,iphostport" help:"list of parent DNS servers (ipv4 or domain). If port is missing default value 53 is used; e.g: '10.0.0.1,10.20.20.0.1:5053,edge.test:53'"`

	FallbackEdgeDNSServerNameRaw string `env:"EDGE_DNS_SERVER" optional:"" help:"deprecated; to avoid breaking changes is used as fallback server port for ParentZoneDNSServers"`

	FallbackEdgeDNSServerPortRaw int `env:"EDGE_DNS_SERVER_PORT" optional:"" default:"53" help:"deprecated; to avoid breaking changes is used as fallback server port for ParentZoneDNSServers"`

	ExtClustersGeoTagsRaw []string `env:"EXT_GSLB_CLUSTERS_GEO_TAGS" optional:"" validate:"unique,dive,geotag" help:"identify clusters gek tags in other locations; separated by comma. i.e.: 'eu,uk,us'"`

	ReconcileRequeueSeconds int `env:"RECONCILE_REQUEUE_SECONDS" optional:""  default:"30" validate:"min=0" help:"delay between individual reconciliations. If set to 0, reconciliation is only triggered at startup or when the GSLB, Ingress, or DNSEndpoint changes."`

	NSRecordTTL int `env:"NS_RECORD_TTL" optional:"" default:"30" validate:"min=1" help:"TTL of the NS and respective glue record used by external DNS."`

	K8gbNamespace string `env:"POD_NAMESPACE" optional:"" default:"k8gb" help:"namespace where k8gb pod is running"`

	CoreDNSExposed bool `env:"COREDNS_EXPOSED" optional:"" default:"false" help:"deprecated; ignored"`

	CoreDNSServiceType corev1.ServiceType `env:"COREDNS_SERVICE_TYPE" required:"" enum:"ClusterIP,LoadBalancer,NodePort,ExternalName" default:"ClusterIP" help:"k8gb requires the cluster IP addresses to operate. If the service type is LoadBalancer, the IP addresses are read from the CoreDNS service otherwise, they are read from the ingress labeled with 'k8gb.io/ip-source=true'."`

	ExtDNSEnabledRaw bool `env:"EXTDNS_ENABLED" optional:"" default:"false" help:"if true K8gb uses ExternalDNS"`

	MetricsAddress string `env:"METRICS_ADDRESS" optional:"" default:"0.0.0.0:8080" validate:"iphostport" help:"format address:port where address can be empty, IP address, or hostname, e.g: 10.10.0.0:8080"`

	TracingEnabled bool `env:"TRACING_ENABLED" optional:"" default:"false" help:"decides whether to use a real otlp tracer or a noop one"`

	TracingSamplingRatio float64 `env:"TRACING_SAMPLING_RATIO" optionl:"" default:"1.0" help:"how many traces should be kept and sent (1.0 - all, 0.0 - none)"`

	OtelExporterOtlpEndpoint string `env:"OTEL_EXPORTER_OTLP_ENDPOINT" optional:"" default:"localhost:4318" help:"where the traces should be sent to (in case of otel collector deployed on the same pod as sidecar -> localhost:4318). Otel collector itself can be configured via a configmap to send it somewhere else"`

	// Infoblox configuration
	Infoblox Infoblox `embed:""`

	Log Log `embed:""`

	DelegationZones DelegationZones

	// EdgeDNSType is READONLY and is set automatically by configuration
	EdgeDNSType EdgeDNSType

	// ParentZoneDNSServers
	ParentZoneDNSServers utils.DNSList
}

// Infoblox configuration
type Infoblox struct {
	// Host
	Host string `env:"INFOBLOX_GRID_HOST" optional:""`
	// Port
	Port int `env:"INFOBLOX_WAPI_PORT" optional:"" default:"53"`
	// Username
	Username string `env:"INFOBLOX_WAPI_USERNAME" optional:""`
	// Password
	Password string `env:"INFOBLOX_WAPI_PASSWORD" optional:""`
	// Version
	Version string `env:"INFOBLOX_WAPI_VERSION" optional:"" default:"v2"`
	// HTTPRequestTimeout seconds
	HTTPRequestTimeout int `env:"INFOBLOX_HTTP_REQUEST_TIMEOUT" optional:"" default:"20" help:"request timeout seconds"`
	// HTTPPoolConnections seconds
	HTTPPoolConnections int `env:"INFOBLOX_HTTP_POOL_CONNECTIONS" optional:"" default:"10" help:"pool connection seconds"`
	// DNSView specifies the DNS view to use for zone operations
	DNSView string `env:"INFOBLOX_DNS_VIEW" optional:"" default:"default" help:"DNS view to use for zone operations"`
}
